﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace dataDict
{
    /// <summary>
    ///  过滤显示内容窗体
    /// </summary>
    public partial class FilterFrm : Form
    {
        /// <summary>
        ///  过滤显示内容窗体构造函数
        /// </summary>
        public FilterFrm ( )
        {
            InitializeComponent ( );
        }
        /// <summary>
        ///  按钮：确定过滤字符，关闭窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOK_Click ( object sender , EventArgs e )
        {

            StringBuilder FilterStr = new StringBuilder ( );
            FilterStr.Append ( "1=1" );
            if (!string.IsNullOrEmpty ( this.textBoxTableName.Text ))
            {
                if (this.comboBox1.Text == "等于")
                {
                    FilterStr.Append ( " and table_name ='" + this.textBoxTableName.Text.Trim ( ).ToUpper ( ) + "'" );

                }
                else
                {
                    FilterStr.Append ( " and table_name like '%" + this.textBoxTableName.Text.Trim ( ).ToUpper ( ) + "%'" );
                }

            }

            if (!string.IsNullOrEmpty ( this.textBoxDesc.Text ))
            {
                if (this.comboBox2.Text == "等于")
                {
                    FilterStr.Append ( " and table_comment ='" + this.textBoxDesc.Text.Trim ( ).ToUpper ( ) + "'" );
                }
                else
                {
                    FilterStr.Append ( " and table_comment like '%" + this.textBoxDesc.Text.Trim ( ).ToUpper ( ) + "%'" );
                }

            }

            if (!string.IsNullOrEmpty ( this.textBoxCollates.Text ))
            {
                if (this.comboBox3.Text == "等于")
                {
                    FilterStr.Append ( " and collates ='" + this.textBoxCollates.Text.Trim ( ).ToUpper ( ) + "'" );
                }
                else
                {
                    FilterStr.Append ( " and collates like '%" + this.textBoxCollates.Text.Trim ( ).ToUpper ( ) + "%," );
                }
            }

            main frm = (main)this.Owner;
            if (FilterStr.Length > 3)
            {
                frm.FilterStr = FilterStr.ToString ( );
            }
            else
            {
                frm.FilterStr = "";
            }

            this.Close ( );
        }
        /// <summary>
        ///  按钮： 取消过滤条件，关闭窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonCancel_Click ( object sender , EventArgs e )
        {
            main frm = (main)this.Owner;
            frm.FilterStr = "";
            this.Close ( );
        }
        /// <summary>
        ///  窗体载入事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FilterFrm_Load ( object sender , EventArgs e )
        {
            this.comboBox1.SelectedIndex = 0;
            this.comboBox2.SelectedIndex = 0;
            this.comboBox3.SelectedIndex = 0;
        }
        /// <summary>
        ///  按钮：清除过滤条件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonClear_Click ( object sender , EventArgs e )
        {
            this.textBoxCollates.Text = "";
            this.textBoxDesc.Text = "";
            this.textBoxTableName.Text = "";
        }
    }
}
